#ifndef DIST_CALCULATOR_H
#define DIST_CALCULATOR_H
#include "bit_extractor.h"
#include "constants.h"
#include <cstdlib>
#include <iostream>

class DistCalculator2
{
public:
    DistCalculator2()
    {
        numOnes_[0] = 0;
        for(size_t i = 1; i < SIZE_VMSK; ++i) {
            numOnes_[i] = (i & 1) + numOnes_[i >> 1];
        }
    }

    unsigned char operator() (size_t a, size_t b) const
    {
        return numOnes_[a ^ b];
    }

    unsigned char operator() (size_t a) const
    {
        return numOnes_[a];
    }

private:
    unsigned char numOnes_[SIZE_VMSK];
};

class DistCalculator3
{
public:
    unsigned char operator() (size_t a, size_t b) const
    {
        unsigned char res = dist2(a & (SIZE_VMSK - 1), b & (SIZE_VMSK - 1));
        //std::cout << "!" << (int)res << std::endl;
        size_t df2 = (a >> n) ^ (b >> n);
        size_t df1 = (~(a ^ b)) & df2;
        res += 4 * dist2(df1);
        //std::cout << "@" << (int)res << std::endl;
        return res;
    }

private:
    DistCalculator2 dist2;
};

const DistCalculator3 distanceCalculator;

#endif//DIST_CALCULATOR_H
